/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaProTableColumns, MaProTableExpose } from "@mineadmin/pro-table";
import type { UseDialogExpose } from "@/hooks/useDialog.ts";

import defaultAvatar from "@/assets/images/defaultAvatar.jpg";
import { ElTag } from "element-plus";
import { useMessage } from "@/hooks/useMessage.ts";
import { ResultCode } from "@/utils/ResultCode.ts";
import hasAuth from "@/utils/permission/hasAuth.ts";
import { deleteByIds } from "@/plugins/ai-warning/alarm/api/rdAlarmBroadcastRecord.ts";

export default function getTableColumns(
  dialog: UseDialogExpose,
  formRef: any,
  t: any
): MaProTableColumns[] {
  const msg = useMessage();

  return [
    {
      type: "selection",
      showOverflowTooltip: false,
      label: () => t("crud.selection"),
    },

    { label: "播放时长（秒）", prop: "second" },
    {
      label: "类型",
      prop: "type",
      cellRender: ({ row }) => {
        return h(ElTag, { type: row.type === 1 ? "success" : "danger" }, () =>
          row.type == 1 ? "广播" : "喊话"
        );
      },
    },
    {
      label: "开始时间",
      prop: "start_time",
      cellRender: ({ row }) => {
        return new Date(row.start_time * 1000).toLocaleString();
      },
    },
    {
      label: "结束时间",
      prop: "end_time",
      cellRender: ({ row }) => {
        return new Date(row.end_time * 1000).toLocaleString();
      },
    },
    {
      label: "广播设备id",
      prop: "device",
      cellRender: ({ row }) => {
        return row.device.join(",");
      },
    },
    {
      type: "operation",
      label: () => t("crud.operation"),
      fixed: "right",
      width: 100,
      operationConfigure: {
        actions: [
          {
            name: "del",
            icon: "mdi:delete",
            text: () => t("crud.delete"),
            show: ({ row }) => hasAuth("alarm:rdAlarmBroadcastRecord:delete"),
            onClick: ({ row }, proxy: MaProTableExpose) => {
              msg.delConfirm(t("crud.delDataMessage")).then(async () => {
                const response = await deleteByIds([row.id]);
                if (response.code === ResultCode.SUCCESS) {
                  msg.success(t("crud.delSuccess"));
                  proxy.refresh();
                }
              });
            },
          },
        ],
      },
    },
  ];
}
